package com.accelstack.cmp.service;

import com.accelstack.cmp.entity.WarrantyInfo;
import com.accelstack.cmp.enums.AssetType;
import com.accelstack.cmp.repository.WarrantyInfoRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

/**
 * 保修信息Service
 */
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class WarrantyInfoService {
    
    private final WarrantyInfoRepository warrantyInfoRepository;
    
    @Transactional
    public WarrantyInfo create(WarrantyInfo warrantyInfo) {
        return warrantyInfoRepository.save(warrantyInfo);
    }
    
    @Transactional
    public WarrantyInfo update(WarrantyInfo warrantyInfo) {
        return warrantyInfoRepository.save(warrantyInfo);
    }
    
    @Transactional
    public void deleteById(Long id) {
        warrantyInfoRepository.deleteById(id);
    }
    
    public Optional<WarrantyInfo> findById(Long id) {
        return warrantyInfoRepository.findById(id);
    }
    
    public List<WarrantyInfo> findAll() {
        return warrantyInfoRepository.findAll();
    }
    
    public Page<WarrantyInfo> findAll(Pageable pageable) {
        return warrantyInfoRepository.findAll(pageable);
    }
    
    public List<WarrantyInfo> findByAssetTypeAndAssetId(AssetType assetType, Long assetId) {
        return warrantyInfoRepository.findByAssetTypeAndAssetId(assetType, assetId);
    }
}

